<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 16-11-10
 * Time: 下午11:17
 */
$dirList = explode ( '/', $_SERVER ['PHP_SELF'] );
$document_root = $_SERVER ["DOCUMENT_ROOT"];
require "$document_root/$dirList[1]/conf/conf.php";
$connMgr = new ConnManger ( $db_conf, $mem_conf );
$connMng = $connMgr->getConn_renren_nuo();

$page_groupId = GROUP_ADMIN_MNG;
$page_pageId = PAGE_ADMIN_MNG;
require "$document_root/$dirList[1]/mng/view/framepages/moudle_base.php";

$admin_user_id = $_GET["admin_user_id"];

$admin_user_record = Rrn_admin_user_DAO::getRecord($admin_user_id, $connMng);
$result = "normal";
$mode=$_POST['mode'];
if($mode == "admin_alter"){

    $admin_user_name = $_POST['admin_name'];
    $admin_user_rank = $_POST['admin_rank'];
    $admin_user_password = $_POST['admin_password'];
    $admin_user_state = $_POST['admin_state'];
    $admin_user_createDate = $_POST['admin_createDate'];
    $admin_user_updateDate = $_POST['admin_updateDate'];
    $admin_user_page = $_POST['super_user_page'];


    $admin_user_record->setName("$admin_user_name");
    $admin_user_record->setRank("$admin_user_rank");
    $admin_user_record->setPassword("$admin_user_password");
    $admin_user_record->setState("$admin_user_state");
    $admin_user_record->setCreatedate("$admin_user_createDate");
    $admin_user_record->setPage(implode(",",$admin_user_page));
    Rrn_admin_user_DAO::update($admin_user_record, $connMng);
    $result = "succ_edit";
}
$admin_user_name = $admin_user_record->getName();
$admin_user_rank = $admin_user_record->getRank();
$admin_user_password = $admin_user_record->getPassword();
$admin_user_state = $admin_user_record->getState();
$admin_user_createDate = $admin_user_record->getCreatedate();
$admin_user_updateDate = $admin_user_record->getUpdatedate();
$admin_user_page = explode(",",$admin_user_record->getPage());

?>
<!--修改管理员-->
<div class="main-content" id="admin_user_alter">
    <div class="row">
        <form id="tab" method="post" action="" onSubmit="javascript:return window.confirm('确认提交吗？')">
            <div class="col-md-4">
                <input type="hidden" name="mode" id="mode" value='admin_alter'>


                <div class="form-group">
                        用户ID：
                       <?php echo $admin_user_id;?>

                </div>

                <div class="form-group">
                        <label for="admin_name">用户名称：</label>
                        <input type="text" class="form-control span12" name="admin_name" id="admin_name" value="<?php echo $admin_user_name; ?>">
                </div>

                <div class="form-group">
                        <label for="admin_rank">用户级别：</label>
                        <input type="text" class="form-control span12" name="admin_rank" id="admin_rank" value="<?php echo $admin_user_rank; ?>">
                </div>

                <div class="form-group">
                        <label for="admin_password">用户密码：</label>
                        <input type="text" class="form-control span12" name="admin_password" id="admin_password" value="<?php echo $admin_user_password; ?>">
                </div>

                <div class="form-group">
                        <label for="admin_createDate">创建时间：</label>
                        <input type="text" class="form-control span12" name="admin_createDate" id="admin_createDate" value="<?php echo $admin_user_createDate; ?>">
                </div>

                <div class="form-group">
                        <label for="admin_updateDate">更新时间：</label>
                        <input type="text" class="form-control span12" name="admin_updateDate" id="admin_updateDate" value="<?php echo $admin_user_updateDate; ?>">
                </div>

                <div class="form-group">
                    <label for="admin_state">管理员状态</label>
                    <select  name="admin_state" id="admin_state">
                        <?php
                            if($admin_user_state==1){
                                echo "<option value=\"1\" selected='selected'>正常</option>
                                        <option value=\"0\">禁用</option>";
                            }else{
                                echo "<option value=\"1\">正常</option>
                                        <option value=\"0\" selected='selected'>禁用</option>";
                            }
                        ?>
                    </select>

                </div>


                <div class="btn-toolbar list-toolbar">
                        <input type="submit" class="btn btn-danger" value="提交">
                </div>
            </div>

            <div class="col-md-4">
                <div class="form-group">
                    <label>权限设置：</label>
                    <?php
                    $group_list = Rrn_mng_group_mst_DAO::getList($connMng);
                    $n=0;
                    foreach ( $group_list as $group ) {
                        $n=0;
                        $group_id = $group->getGroupid();

                        $page_list = Rrn_mng_page_mst_DAO::getList($group_id, $connMng);
                        $group_name = $group->getGroupname();
                        echo "<br> ".$group_name. " : <br>";
                        foreach ($page_list as $page){
                            $n=$n+1;
                            if($n>3){
                                echo "<br>";
                                $n=1;
                            }
                            $page_id = $page->getPageid();
                            $page_name = $page->getPagename();
                            if(in_array($page_id,$admin_user_page)){
                                echo "<input type='checkbox' checked='checked' name='super_user_page[]' "
                                    ."id='$page_id' "
                                    ."value='$page_id'>"
                                    ."&nbsp;$page_name&nbsp;&nbsp;&nbsp;";
                            }else{
                                echo "<input type='checkbox' name='super_user_page[]' "
                                    ."id='$page_id' "
                                    ."value='$page_id'>"
                                    ."&nbsp;$page_name&nbsp;&nbsp;&nbsp;";
                            }
                        }

                    }
                    ?>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    function init(){
        var msg="<?php echo $result;?>"
        if(msg=="succ_edit"){
            alert("修改成功");
        }
    }
</script>